//
//  PostNoteViewController.m
//  DriftDog
//
//  Created by rimi on 15/9/7.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "PostNoteViewController.h"
#import "TopView.h"
#import "CardCell.h"
#import <MJRefresh.h>
#import "SendViewController.h"
@interface PostNoteViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic , strong)UIScrollView *scrollView;
@property (nonatomic , strong)UILabel *labelUser;
@property (nonatomic , strong)UILabel *labelHot;
@property (nonatomic , strong)UILabel *labelLine;
@property (nonatomic , strong)UITableView *tableview;
- (void)initializeUserInterface;

@end

@implementation PostNoteViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self initializeUserInterface];
}

#pragma mark - init

- (void)initializeUserInterface {
    
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.view.backgroundColor=[UIColor whiteColor];
    [self addTitleLabelWithName:@"帖子"];
    [self addBaseRightButtonWithImage:[UIImage imageNamed:@"发帖.png"]];
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.labelUser];
    [self.view addSubview:self.labelHot];
    [self.view addSubview:self.labelLine];
    [self.view addSubview:self.tableview];
    [self.baseRightButton addTarget:self action:@selector(buttonWithRight:) forControlEvents:UIControlEventTouchUpInside];
    for (int i=0; i<4; i++) {
        
        TopView *head=[[TopView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(100*i, 0, 100, 130), NO)];
        head.backgroundColor=[UIColor clearColor];
        [self.scrollView addSubview:head];
        
    }
    
    
    self.tableview.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        
    }];
    
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
    self.tableview.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    
    self.tableview.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
    }];
   
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadMoreData方法）
    self.tableview.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CardCell *cellHigh=[[CardCell alloc]init];
    return (cellHigh.originView.bounds.size.height);
     
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CardCell *cell=[tableView dequeueReusableCellWithIdentifier:@"aaa"];
    if (!cell) {
        cell=[[CardCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"aaa"];
        cell.backgroundColor=[UIColor colorWithRed:219/255.f green:134/255.f blue:67/255.f alpha:1];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}


-(void)buttonWithRight:(UIButton*)sender{
    
    SendViewController *vc=[[SendViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(UIScrollView*)scrollView{
    
    if (!_scrollView) {
        _scrollView=({
            UIScrollView *view=[[UIScrollView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 75, ORIGIN_WIDTH, 130), NO)];
            view.backgroundColor=[UIColor colorWithRed:26/255.f green:146/255.f blue:115/255.f alpha:1];
            view.contentSize=CGSizeMake(4*100, 100);
            view.showsHorizontalScrollIndicator=NO;
            view.showsVerticalScrollIndicator=NO;
            view.bounces=NO;
            view;
        });
    }
    return _scrollView;
    
}

-(UILabel*)labelUser{
    
    if (!_labelUser) {
        _labelUser=({
            
            UILabel *label=[[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(20, 80, 70, 20), NO)];
            label.text=@"热门用户";
            label.backgroundColor=[UIColor clearColor];
            label.textColor=[UIColor whiteColor];
            label.font=[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            label;
        });
    }
    
    return _labelUser;
}

-(UILabel*)labelHot{
    if (!_labelHot) {
        _labelHot=[[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(20, 215, ORIGIN_WIDTH, 30), NO)];
        _labelHot.text=@"狗儿热榜";
        _labelHot.font=[UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
        
    }
    return _labelHot;
    
}

-(UILabel*)labelLine{
    
    if (!_labelLine) {
        _labelLine=[[UILabel alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 215, ORIGIN_WIDTH, 1), NO)];
        _labelLine.backgroundColor=[UIColor grayColor];
        
    }
    return _labelLine;
    
    
}

-(UITableView*)tableview{
    
    if (!_tableview) {
        _tableview=[[UITableView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 245, ORIGIN_WIDTH, ORIGIN_HEIGHT-320), NO) style:UITableViewStylePlain];
        _tableview.backgroundColor=[UIColor whiteColor];
        _tableview.delegate=self;
        _tableview.dataSource=self;
        _tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _tableview;
    
}

-(void)loadNewData{

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.tableview.header endRefreshing];
    });
    
}

-(void)loadMoreData{

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.tableview.footer endRefreshing];
    });

}
@end
